#ifndef classGFGH
 #define classGFGH


 #include "TypeDef.h"
// #include "PrimitivesGFG.h"
 #include "classUARTbuf.h"




/****************************************************************************************************/
/*                              L O W L E V E L     D E F I N E                                     */
/*                               ( d o n ' t     c h a n g e )                                      */
/****************************************************************************************************/
 #define strSize      49

 #define TimeOutCmmn  1500//
 #define TimeOutArch  3500//




/****************************************************************************************************/
/****************************************************************************************************/


/****************************************************************************************************/
/*                          E K 2 7 0   A D D R E S S   C O N S T S                                 */
/*                               ( d o n ' t     c h a n g e )                                      */
/****************************************************************************************************/
 #define StSL_adr         3170  //
 #define StCL_adr         4170  //
 #define CodSL_adr        3171  //
 #define CodCL_adr        4171  //
//
 #define VbT_adr          2302  //
 #define Vo_adr           4302  //
 #define p_adr            7310  //
 #define T_adr            6310  //
//
 #define CO2_adr         11314  //
 #define H2_adr          12314  //
 #define Rhoc_adr        13314  //
 #define N2_adr          14314  //
 #define dv_adr          15314  //
//
 #define Time_adr         1400  //


 #define Idle         0//
 #define Exit         1//
 #define ErrExit      2//


/****************************************************************************************************/
/****************************************************************************************************/






class GFG
{
  char vrgID, ChNumb, CheckSum;
  uint InStrt, NofByte;
  UARTbuf *pUx;
  ArchData D;
  
  
private:  
//
  void setID(void);
  bool askGFG(char Com);
  void formBREAK(void);
  void formREQUEST(void);
  void formACK(char u, char y);
  void formR1(uint Adr, usht NofPar);
  void formR3arch(char NofArch, DataTime *pBgn, char NofStr);
  void formW1(uint Adr);


  void FormCOM40(void);
  void FormCOM41_2(char com, char yy, char mm, char dd);

  void wrChar(char symbol) {(*pUx).WrBufOut(symbol); CheckSum += symbol;};
  void wrCheckSum(void) {wrChar(255-CheckSum+1);};
  void wrBCD(char x) {wrChar(x%10+(x/10%10<<4));};
  char BCDtoCHAR(char bcd)  {return (bcd>>4)*10 + (bcd&0x0F);};
  uint BCDtoUINT(uint bcd);
  float BUFtoFLOAT(void);
  usht BUFtoMIN(void);
  float BUFtoTEMP(void);
  float BUFtoPRES(void);
  usht BUFtoERR(void);
  void NextHour(void);


  void wrString(char *pSTR);
  void wrUShort(usht num);
  void wrDataTime(DataTime *pDT);
  void wrDTval(char DTval);
  void ParamSet(char col);
  void StrToDataTime(DataTime *pDT);
  char StrToChar(uint StrShft);
  bool CheckAnswer(char Com);
//  
public:
//
  GFG(UARTbuf *pUART);
  GFG(UARTbuf *pUART, char VRGid);
  void setVRGID(char VRGid) {vrgID = VRGid;};
  void setChNumb(char chNumb) {ChNumb = chNumb;};
//  void setCodCL(uint CodCL);
  
  
  bool GetCurrentParameters(GFGdata *pCurrData);
//  bool GetGasPassport(GASpassport *pGAS);
  bool GetArMP(DataTime *pRecordTime, GFGarch *pArD);
  bool GetArDay(DataTime *pRecordTime, GFGarch *pArD);
  
  float PutCO2(float CO2percent);
  float PutH2(float H2percent);
  float PutRhoc(float RhocVal);
  float PutN2(float N2percent);
  float PutAnyoneParameter(uint Adr, float Param);
  
  bool startEK(void);
  bool OpenSLcastle(void);
  bool OpenCLcastle(void);
  bool CloseSLcastle(void);
  bool CloseCLcastle(void);
  bool getPARAMfl(uint Adr, float *pParam);
  bool getPARAMdt(uint Adr, DataTime *pDT);
  bool getPARAMui(uint Adr, uint *pParam);
  bool putPARAMui(uint Adr, uint Param);
  bool putPARAMuiHex(uint Adr, uint Param);
  bool putPARAMfl(uint Adr, float Param);
  
  bool getArch(DataTime *pBgn, char NofStr, char NofArh);
  
//
};
/****************************************************************************************************/
/****************************************************************************************************/



#endif